package com.wchen.gdoc.generate.resource.analysis;

import com.sun.javadoc.Type;
import com.wchen.gdoc.generate.config.ApplicationConfigProvide;
import com.wchen.gdoc.generate.resource.structure.FieldStructure;
import com.wchen.gdoc.generate.util.DataTypeUtil;

import java.util.Objects;


/**
 * 列表类型解析器
 *
 * @author  wchen
 * @date    2019/11/7
 */
public class ListTypeDocAnalysis extends AbsGenericAnalysis implements DocTypeAnalysis {

    @Override
    public Boolean isSupport(Type docType) {
//        String fieldTypeName = docType.asClassDoc().qualifiedTypeName();
        String fieldTypeName = docType.qualifiedTypeName();
        return DataTypeUtil.isCollectionData(fieldTypeName);
    }

    @Override
    public FieldStructure analysisParam(Type docType, Boolean isRequestParam) {
        if(ENABLE_DEBUG) {
            LOGGER.info(String.format("execute ListTypeDocAnalysis, docType=%s", docType.toString()));
        }
        String classType = docType.qualifiedTypeName();
        FieldStructure fieldStructure = new FieldStructure();
        fieldStructure.setSimpleName(docType.simpleTypeName());
        fieldStructure.setType(classType);

        //类型比较
        Type genericType = super.calculateType(docType);
        Type gType = super.extractGenericType(docType);
        if(genericType == docType && genericType == gType) {
            return fieldStructure;
        }else if(genericType == docType && genericType != gType) {
            genericType = gType;
        }


        //泛型处理
        FieldStructure genericStructure = executeAnalysis(genericType, isRequestParam);
        if(genericStructure != null) {
            fieldStructure.setGenericType(genericStructure);
            fieldStructure.setGenericTypeName(genericType.qualifiedTypeName());
        }

        return fieldStructure;
    }


}
